package com.sti.platform.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.aisino.core.dao.BaseDao;
import com.aisino.tools.enums.PageEnum;
import com.aisino.tools.enums.QlEnum;
import com.aisino.tools.util.page.Page;
import com.aisino.tools.util.page.Pagination;
import com.sti.platform.dao.RoleDao;
import com.sti.platform.model.Role;
import com.sti.platform.model.UserRole;

@Repository
public class RoleDaoImpl extends BaseDao implements RoleDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Role> queryRole(String params,Integer index,Integer row) {
		Page page = new Pagination();
		page.setPage(index);
		page.setRow(row);
		StringBuilder builder = new StringBuilder();
		String sql = "SELECT * FROM sys_role where 1=1";
		builder.append(sql);
		if(params != null && !"".equals(params)){
			builder.append(" and name LIKE '%"+params+"%' ");
		}
		
		Integer count = super.getTotalCount(builder.toString(), null, null, QlEnum.SQL);
		page.setTotal(count);
		return super.getByHibernateQuery(builder.toString(), null, null, 1000, page, Role.class,QlEnum.SQL, PageEnum.PAGE_YES).getRecord();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserRole> queryUserRole(String roleId) {
		String sql = "SELECT * FROM sys_user_role WHERE role_id = '" + roleId + "'";
		return super.getBySql(sql, UserRole.class);
	}
}
